package com.example.controller.admin;

import com.example.common.Result;
import com.example.entity.DTO.TeacherDetailDTO;
import com.example.entity.Teacher;
import com.example.service.admin.TeacherService;
import jakarta.annotation.Resource;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/admin")
public class TeacherController {
    @Resource
    private TeacherService teacherService;

    /**
     * 获取全部教师详细信息
     */
    @GetMapping("/selectAllTeacher")
    public Result selectAllTeacher(@RequestParam(defaultValue = "") String teacherName,
                                   @RequestParam(defaultValue = "") String deptName) {
        List<TeacherDetailDTO> TeacherDetailDTOS = teacherService.selectAllTeacher(teacherName, deptName);
        return Result.success(TeacherDetailDTOS);
    }

    /**
     * 根据工号获取单个教师信息
     */
    @GetMapping("/selectTeacher")
    public Result selectTeacher(@RequestParam(defaultValue = "") String username) {
        Teacher teacher = teacherService.selectTeacher(username);
        return Result.success(teacher);
    }

    /**
     * 添加教师
     */
    @PostMapping("/addTeacher")
    public Result addTeacher(@RequestBody Teacher teacher) {
        teacherService.addTeacher(teacher);
        return Result.success();
    }

    /**
     * 更新教师信息
     */
    @PutMapping("/updateTeacher")
    public Result update(@RequestBody Teacher teacher) {
        teacherService.updateTeacher(teacher);
        return Result.success();
    }

    /**
     * 删除教师
     */
    @DeleteMapping("/deleteTeacher/{id}")
    public Result deleteTeacher(@PathVariable Integer id) {
        teacherService.deleteTeacher(id);
        return Result.success();
    }
}
